<%
var headerPart = {
%>
<script type="text/javascript">
    function page(n,s){
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
</script>
<% }; %>
<% layout("/layouts/micro.html",{headerSection:headerPart}){ %>
<div class="layui-fluid">
	<div class="layui-card">
	<!--<div class="layui-tab layui-tab-brief childrenBody">
	<ul class="layui-tab-title">
		<li class="layui-this"><a href="${ctx}/cms/link/?category.id=${link.category.id}">链接列表</a></li>
		<%if(shiro.hasPermission("cms:link:edit")){%><li><a href="${ctx}/cms/link/form?id=${link.id}&category.id=${link.category.id}&category.name=${link.category.name}">链接添加</a></li><%}%>
	</ul>
	<div class="layui-tab-content">-->
	<form id="searchForm" action="${ctx}/cms/link/" method="post" class="layui-form layui-card-header layuiadmin-card-header-auto">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">栏目：</label>
				<div class="layui-input-block">
					<#treeselect id="category" name="category.id" value="${link.category.id}" labelName="category.name" labelValue="${link.category.name}"
						title="栏目" url="/cms/category/treeData" module="link" notAllowSelectRoot="false" cssClass="input-small"/>
				</div>
			</div>

			<div class="layui-inline">
				<label class="layui-form-label">名称：</label>
				<div class="layui-input-block">
					<input type="text" name="title" htmlEscape="false" maxlength="50" class="layui-input"/>
				</div>
			</div>

			<div class="layui-inline">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-block">
					<#radio name="delFlag" items="${@DictUtils.getDictList('cms_del_flag')}" value="${link.delFlag }" />
				</div>
			</div>

			<div class="layui-inline">
				<button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-enrollList-search">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
			</div>
		</div>
	</form>
	<div class="layui-card-body">
		<#message content="${message!}"/>
		<%if(shiro.hasPermission("cms:link:edit")){%>
		<div>
			<button class="layui-btn layui-btn-normal LAY_ADD_link_btn"><i class="layui-icon layui-icon-add-1"></i>链接添加</button>
		</div>
		<%}%>
		<table id="contentTable" class="layui-table" >
			<thead>
				<tr>
					<th style="text-align:center">栏目</th>
					<th style="text-align:center">名称</th>
					<th style="text-align:center">权重</th>
					<th style="text-align:center">发布者</th>
					<th style="text-align:center">更新时间</th>
					<%if(shiro.hasPermission("cms:link:edit")){%>
						<th style="text-align:center">操作</th>
					<%}%>
				</tr>
			</thead>
			<tbody>
				<%for(link in page.list){%>
				<tr>
					<td style="text-align:center">${link.category.name}</td>
					<td style="text-align:center">${@StringUtils.abbr(link.title,40)}</td>
					<td style="text-align:center">${link.weight}</td>
					<td style="text-align:center">${link.user.name}</td>
					<td style="text-align:center">${link.updateDate,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
					<%if(shiro.hasPermission("cms:link:edit")){%>
						<td style="text-align:center">
							<a class="layui-btn layui-btn-xs" onclick="editLink('${link.id}')" href="javascript:void(0);">修改</a>
							<a class="layui-btn layui-btn-danger layui-btn-xs" href="${ctx}/cms/link/delete?id=${link.id}${link.delFlag != '0'?'&isRe=true':''}&categoryId=${link.category.id}" onclick="return confirmx('确认要${link.delFlag != '0'?'发布':'删除'}该链接吗？', this.href)" >${link.delFlag != '0'?'发布':'删除'}</a>
						</td >
					<%}%>
				</tr>
				<%}%>
			</tbody>
		</table>
		<div class="pagination">${page}</div>
	</div>
	</div>
</div>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        //添加
        $(".LAY_ADD_link_btn").click(function(){
            var index = layui.layer.open({
                title : "添加链接",
                type : 2,
                content : "${ctx}/cms/link/form?id=${link.id}&category.id=${link.category.id}&category.name=${link.category.name}",
                maxmin: true,
                area: ['100%', '100%'],
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#linkForm');
                    submit.trigger('click');
                    layer.close(index);
                },
                end:function(){
                    location.reload();
                }
            })
        })
    })
    var editLink = function(id){
        var index = layui.layer.open({
            title : "修改链接",
            type : 2,
            content : "${ctx}/cms/link/form?id="+id,
            maxmin: true,
            area: ['100%', '100%'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#linkForm');
                submit.trigger('click');
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
</script>
<%}%>